import {useLoading} from '@/hooks/loading'
import useModal from '@/hooks/modalHook'
import {ant_design_vue} from '@/libs/global/antDesignVue'
import {getSession} from '@/libs/sessionStorage'
import { defineComponent, reactive, watch, onMounted} from 'vue'
const {message} = ant_design_vue

const AddManagerModal = defineComponent({
  props: {
    visible: Boolean,
    pmId: Number
  },
  emits: {
    'update:visible': (data: boolean): boolean => true,
    confirm: (): boolean => true
  },
  setup(props, {emit}) {
    const {visible, openModal, closeModal} = useModal()

    const {loading, startLoading, closeLoading} = useLoading()

    let state = reactive<{}>({})

    watch(
      () => props.visible,
      n => {
        if (n) {
          openModal()
        } else {
          closeModal()
        }
      },
      {immediate: true}
    )

    watch(
      () => visible.value,
      n => {
        emit('update:visible', n)
        // 关闭后清空状态
        if (!n) {
        }
      }
    )

    function handleModalConfirm() {
      let makeUserDDId = getSession('userDDId') as string
      if (!makeUserDDId) return message.warning('请刷新页面')
    }

    onMounted(() => {})

    return () => (
      <a-modal
        class='custom-modal w-1/3'
        title='发起评分'
        v-model={[visible.value, 'visible']}
        onOk={handleModalConfirm}
        cacelButtonProps={{
          loading: loading.value
        }}
        confirmLoading={loading.value}
      >
        <div class='my-8 p-8'></div>
      </a-modal>
    )
  }
})

export default AddManagerModal
